{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 梯度下降法SDG\n",
    "数组x，基于表达式：$y = 3x^2+2 $   加上一些噪声数据得到y\n",
    "然后学习表达式$y = wx^2+b $ 中的w与b 两个参数，这里采用梯度下降法。"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from matplotlib import pyplot as plt"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "# 构造数据\n",
    "np.random.seed(100)  # 设置随机数种子\n",
    "x = np.linspace(-1, 1, 100).reshape(100, 1)\n",
    "y = 3 * np.power(x, 2) + 2 + 0.2 * np.random.rand(x.size).reshape(100, 1)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAeHklEQVR4nO3df5AcZ33n8fdX67W1DqAV9obYawuJOkdcEsNusuX4TlcXLBIEhpIVY066Kic2gdJBUoftBOXWocoHrrqyOKfOvjuS+FQmFxNyoESAT2Bysojs4nBhJyu0trGNQPxI4bUPLbbXgWhRVtL3/phuqbfVPdM90zPT3fN5VW1pdrp35lHv7HeeeZ7v833M3RERkepb0e8GiIhIM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Rfw6zTGkY4DPwD2BfdfDHwxct7VwDdpvMN+KHL/62j8wR0B/go4r6B2XQD8DfAt4EvAq4P7p4B7I+etpfGuuyL28weAJ2kEpk8Cr+hVu4B/GTz348G/7ynD9QKuB5aA2cjXRDeuV9LrhcYQzubg9srg/38kuB6vi/zsh4KfOwy8reDXe6t2fSn4Owivz95Wv9MetesO4Kng+R8CXh/52d8KruMR4N29bFfw/YeBnbGf6/b1+hSNLK0lGvHrPcD7gPcFxw34o6DdTxLJ4Cviemnpv4hITVR9yEVERAIK6CIiNaGALiJSEwroIiI1oYAuIlITCugiIjWhgC4iUhP/H7bfJ07iOrkMAAAAAElFTkSuQmCC\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 绘制散点图\n",
    "plt.scatter(x, y)\n",
    "plt.show()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [],
   "source": [
    "# 初始化随机参数\n",
    "w1 = np.random.rand(1, 1)\n",
    "b1 = np.random.rand(1, 1)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [],
   "source": [
    "# 训练模型  梯度下降法\n",
    "lr = 0.001\n",
    "epochs = 1000\n",
    "for i in range(epochs):\n",
    "    # 前向传播  y* = w1*x^2+b1  来 拟合 y = 3x^2 + 2   求w1 和 b1\n",
    "    y_pred = np.power(x, 2) * w1 + b1\n",
    "    # loss\n",
    "    loss = 0.5 * (y_pred - y) ** 2  # 损失函数  (y-y*)^2/2\n",
    "    loss = loss.sum()\n",
    "    # 计算梯度\n",
    "    grad_w = np.sum((y_pred - y) * np.power(x, 2))  # 导数\n",
    "    grad_b = np.sum((y_pred - y))  # 导数\n",
    "    # 使用梯度下降，min loss\n",
    "    w1 -= lr * grad_w\n",
    "    b1 -= lr * grad_b"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "(array([[2.99094577]]), array([[2.09756449]]))"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w1,b1"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX8AAAD8CAYAAACfF6SlAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAA3AElEQVR4nO3deXhTZfbA8e9paSllEawVF6DFEQTcECqi4Io6qAyoIyqCCyIFRBFwKYoiogjuu0JH+IlQN1QUHReYQVxBBxxAZBOYtizKqgiUtT2/P25S0jRt0zZrcz7Pk6fJvW9u3t4kJ+99V1FVjDHGxJa4cGfAGGNM6FnwN8aYGGTB3xhjYpAFf2OMiUEW/I0xJgZZ8DfGmBjkV/AXkYYi8q6IrBCR5SJyptd+EZHnRWS1iCwRkXbBya4xxphAqOVnuueAz1T1KhFJBJK99l8CtHDdzgBecf01xhgTgSos+YvIYcA5wCQAVd2vqn94JesBvK6O+UBDETk60Jk1xhgTGP6U/JsDW4D/E5FTgYXAHaq62yPNscA6j8frXdt+9TyQiGQCmQB169Zt36pVq2pk3RhjYs/ChQu3qmpqdY/jT/CvBbQDblfV70XkOWAE8EBlX0xVs4FsgIyMDF2wYEFlD2GMMTFNRPICcRx/GnzXA+tV9XvX43dxfgw8bQCaejxu4tpmjDEmAlUY/FX1N2CdiJzg2tQFWOaVbCZwg6vXT0dgh6r+ijHGmIjkb2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01R1g4gcB8wRkZ9wgljABPh8TgVuVNUi1+aAnc+aTkT6ABnAuR6bS73/qrrG9xGC7iPgTVXdJyIDcK6qLghTXvxxLfCuqhZ6bIuk8xkw1Q7+qnphNQ9R1tQQ23Aua2q5SmDVmjKivHyKyCYROVpVf3UFo83lHOpqYIaqHvA4truUu09E/g+4K5z5VNUNrr9rRWQucBrO9BwRdT5FpAHwT5yCwnyPYwfsfHrxZxoSd5r1IlILOAznsxjKKUz8ei0RuRDnx/ZcVd3n3l7G+x+MYFVhPlV1m8fDV3Hag9zPPc/ruXMDnsNDr+Xve3ctMNhzQwjPZ0XK+j+qdC4jodrnP0ALcXqiJOKc/JnqtGR8gVO/DnAjEKwriZmu4/vzOqXqA10Bzl2vfjnBm620wnyKSCN3NYmIHIEzQntZpJ1P13s9A6cO812vfcE6nz4/a+Xk/SpgjuvczQSuFac3UHOctSt+CFC+Kp1PETkNmAh0V9XNHtt9vv9hzOfRHg+7A8td9z8HLnbltxFwMSWvpkOaT1deW+E0mM7z2BbK81mRsqbRqdq5DHLr9RU49U/7gE3A567txwCfeLVir8L5NR3psf04nC/YamA6UDtI+UwB/g38AvwLONy1PQN41SNdOs6vbJzX8+cAP+EEqWlAvXDlEzjLlZfFrr/9IvF8An2AA8Aij1vbYJ9PX581nCql7q77Sa5zs9p1ro7zeO5I1/NWApcE+btTUT7/5fpOuc/dzIre/zDlcxzwsys/XwCtPJ57s+s8rwb6hjOfrsejcaam93xeyM4nTqHyV9f3Yj1OW85AYKBrvwAvuf6Hn/DoQVmVc2nTOxhjTAyKhGofY4wxIWbB3xhjYpAFf2OMiUEW/I0xJgZZ8DfGmBhkwd8YY2KQBX9jjIlB/w/dLIEcwsK6cQAAAABJRU5ErkJggg==\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 可视化结果\n",
    "plt.plot(x,y_pred,'r-',label='predict')\n",
    "plt.scatter(x,y,color='blue',marker='o',label='true')\n",
    "plt.xlim(-1,1)\n",
    "plt.ylim(2,6)\n",
    "plt.legend()\n",
    "plt.show()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}